<template>
	<div>
		<uni-page-header title="邀好友注册的积分活动" />
		<div class="header">
			<image :src="imageSrc" mode="widthFix" class="header-img"></image>
			<button open-type="share" class="share">{{t_text1}}</button>
		</div>
		<u-subsection :list="list" :current="current" @change="sectionChange"></u-subsection>
		<u-cell-group v-if="current == 0">
			<u-cell :title="item.name" arrow-direction="down" :value="item.create_date" :icon="item.avatar"
				v-for="(item, index) in customer_list" :key="index"></u-cell>
		</u-cell-group>

		<u-cell-group v-if="current == 1">
			<u-cell title="邀请入会" arrow-direction="down" :value="'+' + item.points" :label="item.create_date"
				v-for="(item, index) in reward_list" :key="index"></u-cell>
		</u-cell-group>

	</div>
</template>

<script>
	import {
		getCurrentPageConfigByName,
		getImg
	} from '@/utils/index.js'
	import {
		wx_customer_recommend_list,
		wx_customer_share_prefetch,
		wx_reward_recommend_list,
		wx_customer_share_upd
	} from '@/api'
	import dayjs from 'dayjs'
	import shareMixin from '@/mixins/shareMixin'
	export default {
		mixins: [shareMixin],
		data() {
			return {
				imageSrc: '',
				t_text1: '',
				list: ['邀请成功记录', '奖励记录'],
				current: 0,
				customer_list: [],
				reward_list: []
			}
		},
		methods: {
			sectionChange(index) {
				this.current = index;
			},
			handleShareInfo() {
				const promise = new Promise((resolve, reject) => {
					wx_customer_share_prefetch({
						type: 10,
						source_id: 60,
					}).then(res => {
						wx_customer_share_upd({
							type: 10,
							share_id: res.share_id,
							source_id: 60
						})
						resolve({
							path: `pages/home?share_id=${res.share_id}`
						})
					})
				})
				return {
					promise
				}
			},
		},
		onLoad() {
			getCurrentPageConfigByName('邀请').then(res => {
				console.log('邀请', res)
				this.imageSrc = getImg(res.bg_image)
				this.t_text1 = res.t_text1
			})
			wx_customer_recommend_list().then(res => {
				this.customer_list = res.customer_list.map(item => {
					item.create_date = dayjs(item.create_date).format('YYYY.MM.DD HH:mm')
					return item
				})
			})
			wx_reward_recommend_list().then(res => {
				this.reward_list = res.reward_list.map(item => {
					item.create_date = dayjs(item.create_date).format('YYYY.MM.DD HH:mm')
					return item
				})
			})
		}
	}
</script>

<style lang="scss" scoped>
	.header {
		margin: 20rpx;
		position: relative;

		&-img {
			width: 100%;
		}
	}

	.share {
		width: 60%;
		height: 70rpx;
		line-height: 70rpx;
		border-radius: 15rpx;
		background-color: $theme-color;
		position: absolute;
		left: 50%;
		transform: translateX(-50%);
		bottom: 20%;
	}
</style>